package com.lwlk.zdk.controller.Excel;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lwlk.zdk.annotation.JwtIgnore;
import com.lwlk.zdk.enums.RetCode;
import com.lwlk.zdk.mapper.T.*;
import com.lwlk.zdk.model.Encapsulation.EncapsulationTired;
import com.lwlk.zdk.model.T.TDisPlatform;
import com.lwlk.zdk.service.Log.SysLogService;
import com.lwlk.zdk.service.PostService.PostMessageService;
import com.lwlk.zdk.util.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.commons.lang.time.DateUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/*
* excel表
* */
@RestController
public class NetInExcelController {

    private final static String port = PropUtils.getString("ports");
    private final static String Ip = PropUtils.getString("Ip");
    private final static String clientCode = PropUtils.getString("clientCode");

    private static final Logger log = LoggerFactory.getLogger(NetInExcelController.class);

    @Autowired
    TDisDictionaryMapper disDictionaryMapper;
    @Autowired
    TRegionMapper tRegionMapper;
    @Autowired
    TDisEnterpriseMapper tDisEnterpriseMapper;
    @Autowired
    TDisVehicleMapper tDisVehicleMapper;
    @Autowired
    TDisPlatformMapper tDisPlatformMapper;
    @Autowired
    TDisMismatchVehicleMapper disMismatchVehicleMapper;
    @Autowired
    private SysLogService sysLogService;
    @Autowired
    TDisDictionaryMapper tDisDictionaryMapper;
    @Autowired
    TDisVehicleMapper disVehicleMapper;
    @Autowired
    PostMessageService postMessageService;

    @ApiOperation(value = "车辆入网统计导出按钮")
    @RequestMapping(value = "/AccessStatisticsExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void outAccessStatisticsExcelOut(HttpServletResponse response,Integer oid,String netstatus,String startTime,String endTime,Integer size,Integer page,String eid,String pName,String vNumber,Integer level,HttpServletRequest request){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb=new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet=wb.createSheet("车辆入网统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row=sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell=row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆入网统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
            //在sheet里创建第二行
            XSSFRow row2=sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("企业名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("车牌颜色");
            row2.createCell(4).setCellValue("是否入网");
            row2.createCell(5).setCellValue("入网时间");
            if (startTime.equals("null")&&endTime.equals("null")){
                startTime=null;
                endTime=null;
            }
            Integer netstatu=null;
            if (netstatus.equals("null")){
                netstatu=null;
            }else {
                netstatu=Integer.parseInt(netstatus);
            }
            Integer regionCode=null;
            if (level==1){
                regionCode= Integer.valueOf(String.valueOf(oid).substring(0,2));
            }else if (level==2){
                regionCode= Integer.valueOf(String.valueOf(oid).substring(0,4));
            }else if (level==3){
                regionCode= oid;
            }
            List<Map> pIdsList=new ArrayList<>();
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()<0){

                }
            }
            if (pName!=null && pName.equals("")==false){
                pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
                if (pIdsList.size()<0){

                }
            }
            Integer eId=null;
            if (eid==null || eid.equals(null) || eid.equals("null")){
                eId=null;
            }else {
                eId= Integer.valueOf(eid);
            }
            Integer pageNum=(page-1)*size;
            List<Map<String,Object>>vehicleNet=new LinkedList<>();
                if (pIdsList.size()>0){
                    for (int j = 0; j < pIdsList.size(); j++) {
                        Map pIdMap=pIdsList.get(j);
                        vehicleNet=tDisEnterpriseMapper.selectVehicleNet(regionCode,netstatu,startTime,endTime,eId,Integer.parseInt(String.valueOf(pIdMap.get("platform_id"))),vNumber,pageNum,size);
                    }
                }else {
                    vehicleNet=tDisEnterpriseMapper.selectVehicleNetAll(regionCode,netstatu,startTime,endTime,eId,null,vNumber,pageNum,size);
                }


            for (int i = 0; i < vehicleNet.size(); i++) {
                Map map=vehicleNet.get(i);
                String enterpriseName=String.valueOf(map.get("enterprise_name"));
                if (enterpriseName.equals("null")){
                    enterpriseName="";
                }
                String platformName=String.valueOf(map.get("platform_name"));
                if (platformName.equals("null")){
                    platformName="";
                }
                String vehicleNumber=String.valueOf(map.get("vehicle_number"));
                if (vehicleNumber.equals("null")){
                    vehicleNumber="";
                }
                String vehicleColor=String.valueOf(map.get("vehicle_license_color"));
                String vehicleColorName=disDictionaryMapper.selectVehicleColor(vehicleColor);
                if (vehicleColorName==null){
                    vehicleColor="";
                }
                String netState=String.valueOf(map.get("networkState"));
                if (netState.equals("null")){
                    netState="";
                }
                String netTime=String.valueOf(map.get("netTime"));
                if (netTime.equals("null")){
                    netTime="";
                }
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(platformName);
                row3.createCell(2).setCellValue(vehicleNumber);
                row3.createCell(3).setCellValue(vehicleColorName);
                row3.createCell(4).setCellValue(netState);
                row3.createCell(5).setCellValue(netTime);
            }
            //输出Excel文件
            OutputStream output=response.getOutputStream();
            String fileName="车辆入网统计表.xls";
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "平台连通性导出按钮")
    @JwtIgnore
    @RequestMapping(value = "/connectStatisticExcelOut",method = RequestMethod.GET)
    public void  getConnectStatisticExcelOut(String startTime,String endTime,String pName,HttpServletRequest request,HttpServletResponse response,String limit,String page){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb=new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet=wb.createSheet("连通性统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row=sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell=row.createCell(0);
            //设置单元格内容
            cell.setCellValue("连通性统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
            //在sheet里创建第二行
            XSSFRow row2=sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("平台名称");
            row2.createCell(1).setCellValue("连通率");
            row2.createCell(2).setCellValue("在线次数");
            row2.createCell(3).setCellValue("在线时长");
            row2.createCell(4).setCellValue("离线次数");
            row2.createCell(5).setCellValue("离线时长");
            String pIdList="";
            String pIds=null;
            if (pName!=null && pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map=new HashMap();
            map.put("startTime",startTime);//查询开始时间yyyy-MM-dd HH:mm:ss
            map.put("pIds",pIds);//平台id,多个id以逗号分隔
            map.put("endTime",endTime);//查询结束时间yyyy-MM-dd HH:mm:ss
            map.put("limit",limit);//页面记录数，默认为10
            map.put("page",page);//页码，默认为1
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str).equals("null")|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/connectStatistic/list";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result) ;
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                BigDecimal onlineCount=BigDecimal.valueOf(Long.parseLong(jsonObject.getString("onlineCount")));//在线次数
                BigDecimal offlineCount=BigDecimal.valueOf(Long.parseLong(jsonObject.getString("offlineCount")));//离线次数
                Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
                String offlineTime=jsonObject.getString("offlineTime");//离线时长
                String onlineTime=jsonObject.getString("onlineTime");//离线时长
                String platformName=tDisPlatformMapper.selectpId(pId);
                DecimalFormat df = new DecimalFormat("0.00%");
                String connectedRate=df.format(onlineCount.divide(onlineCount.add(offlineCount),2,BigDecimal.ROUND_HALF_UP));//连通率
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(platformName);
                row3.createCell(1).setCellValue(connectedRate);
                row3.createCell(2).setCellValue(String.valueOf(onlineCount));
                row3.createCell(3).setCellValue(onlineTime);
                row3.createCell(4).setCellValue(String.valueOf(offlineCount));
                row3.createCell(5).setCellValue(offlineTime);
            }
            //输出Excel文件
            OutputStream output=response.getOutputStream();
            String fileName="连通性统计表.xls";
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "数据合格率导出按钮")
    @RequestMapping(value = "/vehicleDataPassStatisticExcel",method = RequestMethod.GET)
    @JwtIgnore
    public void getVehicleDataPassStatisticExcel(String startDate,String endDate,String limit,String page,String eName,String pName,String vNumber,String regionCode,HttpServletRequest request,HttpServletResponse response) {
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb=new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet=wb.createSheet("车辆数据合格率表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row=sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell=row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆数据合格率表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
            //在sheet里创建第二行
            XSSFRow row2=sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("企业名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("总轨迹数");
            row2.createCell(4).setCellValue("合格轨迹数");
            row2.createCell(5).setCellValue("不合格轨迹数");
            row2.createCell(6).setCellValue("时间");
            String eIdsList="";
            String vIdlist="";
            String pIdList="";
            String eIds=null;
            String vIds=null;
            String pIds=null;
            if (eName!=null && eName.equals("")==false){
                List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
                if (eIdsLists.size()>0){
                    for (int i = 0; i < eIdsLists.size(); i++) {
                        eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                    }
                    eIds=StringUtils.join(eIdsList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (pName!=null && pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map = new HashMap();
            map.put("startDate", startDate);//必选 开始查询日期yyyy-MM-dd
            map.put("endDate", endDate);//必选 结束查询日期yyyy-MM-dd,查询时间不要超过30天
            map.put("regionCode",regionCode);
            map.put("startDate",startDate);//必选 开始查询日期yyyy-MM-dd
            map.put("endDate",endDate);//必选 结束查询日期yyyy-MM-dd,查询时间不要超过30天
            map.put("pIds",pIds);//平台id,多个id英文逗号分隔
            map.put("eIds",eIds);//企业id,多个id英文逗号分隔
            map.put("vIds",vIds);//车辆id,多个id英文逗号分隔
            map.put("regionCode",regionCode);
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if (map.get(str) == null || map.get(str) == "null" || map.get(str) == "") {
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String, String> headMap = new HashMap<>();
            headMap.put("clientCode", clientCode);
            String url = "http://" + Ip + ":" + port + "/dis/v1/statistics/vehicleDataPassStatistic/info";
            String result = HttpClientUtils.doGet(url, headMap, map);
            JSONObject json = JSONObject.parseObject(result);
            JSONObject jo = json.getJSONObject("result");
            JSONArray jsonArray = jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Integer vId = Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer pId = Integer.parseInt(jsonObject.getString("pId"));//平台id
                Integer eId = Integer.parseInt(jsonObject.getString("eId"));//企业id
                String totalGps =jsonObject.getString("totalGps");//总轨迹数
                String passGps =jsonObject.getString("passGps");//合格轨迹数
                String disPassGps = jsonObject.getString("disPassGps");//不合格轨迹数
                String passRate = jsonObject.getString("passRate");//数据合格率
                String date = jsonObject.getString("date");//时间
                String enterpriseName = tDisEnterpriseMapper.selectByEid(eId);
                String platformName = tDisPlatformMapper.selectpId(pId);
                String vehicleName = tDisVehicleMapper.selectByVid(vId);
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(platformName);
                row3.createCell(2).setCellValue(vehicleName);
                row3.createCell(3).setCellValue(totalGps);
                row3.createCell(4).setCellValue(passGps);
                row3.createCell(5).setCellValue(disPassGps);
                row3.createCell(6).setCellValue(date);
            }
            //输出Excel文件
            OutputStream output=response.getOutputStream();
            String fileName="车辆数据合格率表.xls";
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "车辆轨迹完整统计按钮")
    @RequestMapping(value = "/vehicleTrackFullStatisticExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getVehicleTrackFullStatisticExcelOut(String startDate,String endDate,String regionCode,HttpServletRequest request,HttpServletResponse response,String eid,String pName,String vNumber){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("车辆轨迹完整统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆轨迹完整统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("企业名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("连续里程(公里)");
            row2.createCell(4).setCellValue("不连续里程(公里)");
            row2.createCell(5).setCellValue("总里程(公里)");
            row2.createCell(6).setCellValue("轨迹完成度");
            String vIdlist="";
            String pIdList="";
            String vIds=null;
            String pIds=null;
            if (eid==null ||eid.equals("")||eid.equals("null")){
                eid=null;
            }
            if (vNumber!=null&&vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (pName!=null&&pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            NumberFormat nf = java.text.NumberFormat.getPercentInstance();
            Map map=new HashMap();
            map.put("startDate",startDate);//必传 开始查询日期yyyy-MM-dd
            map.put("endDate",endDate);//必传 结束查询日期yyyy-MM-dd
            map.put("vIds",vIds);//车辆id,多个以逗号分隔
            map.put("eIds",eid);//企业id,多个以逗号分隔
            map.put("pIds",pIds);//平台id,多个以逗号分隔
            map.put("regionCode",regionCode);
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==" "){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleTrackFullStatistic/info";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String continueMileage=jsonObject.getString("continueMileage");//连续里程
                String disContinueMileage=jsonObject.getString("disContinueMileage");//不连续里程
                String totalMileage=jsonObject.getString("totalMileage");//总里程
                String trackFullRate=jsonObject.getString("trackFullRate");//轨迹完成度
                double c=Double.valueOf(trackFullRate);
                String trackFullRates=nf.format(c);//将轨迹完成度转成百分数
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);//企业名称
                String platformName=tDisPlatformMapper.selectpId(pId);//平台名称
                String vehicleName=tDisVehicleMapper.selectByVid(vId);//车辆名称
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(platformName);
                row3.createCell(2).setCellValue(vehicleName);
                row3.createCell(3).setCellValue(continueMileage);
                row3.createCell(4).setCellValue(disContinueMileage);
                row3.createCell(5).setCellValue(totalMileage);
                row3.createCell(6).setCellValue(trackFullRates);
            }
            String fileName="车辆轨迹完整统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "报警统计导出按钮")
    @RequestMapping(value = "/alarmTypeAlarmExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getAlarmStatisticsExcelOut(String startDate,String endDate,String regionCode,String vehicleNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("报警统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("报警统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("超速报警");
            row2.createCell(2).setCellValue("疲劳驾驶");
            row2.createCell(3).setCellValue("禁出报警");
            row2.createCell(4).setCellValue("禁入报警");
            row2.createCell(5).setCellValue("紧急报警");
            row2.createCell(6).setCellValue("夜间禁行");
            row2.createCell(7).setCellValue("偏航报警");
            row2.createCell(8).setCellValue("报警总数");
            row2.createCell(9).setCellValue("时间");
            NumberFormat nf = java.text.NumberFormat.getPercentInstance();
            String vIdlist="";
            String vIds=null;
            if (vehicleNumber!=null && vehicleNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vehicleNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map = new HashMap();
            map.put("startDate", startDate);//必传 开始查询日期yyyy-MM-dd
            map.put("endDate", endDate);//必传 结束查询时间yyyy-MM-dd
            map.put("regionCode", regionCode);//必传 用户行政区划编码
            map.put("vIds",vIds);//车辆id,多个id以逗号分隔
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            JSONObject jso = new JSONObject();
            if (vIds==null){
                vIds="";
            }
            String body=jso.toJSONString(vIds);
            String url = "http://" + Ip + ":" + port + "/dis/v1/statistics/alarmType/alarm";
            Map<String, String> headMap = new HashMap<>();
            headMap.put("clientCode", clientCode);
            String path = "/dis/v1/statistics/alarmType/alarm";
            String result=HttpClientUtils.doPostTestFour(path,headMap, map,body);
            JSONObject json = JSONObject.parseObject(result);
            JSONObject jo = json.getJSONObject("result");
            JSONArray jsonArray = jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Integer vId = Integer.parseInt(jsonObject.getString("vId"));//车辆id
                String overspeedCount =jsonObject.getString("overspeedCount");//超速报警
                String emergencyCount =jsonObject.getString("emergencyCount");//紧急报警
                String fatigueDrivingCount =jsonObject.getString("fatigueDrivingCount");//疲劳驾驶
                String forbidOutCount =jsonObject.getString("forbidOutCount");//禁出报警
                String forbidInCount =jsonObject.getString("forbidInCount");//禁入报警
                String nightDrivingCount =jsonObject.getString("nightDrivingCount");//夜间驾驶
                String totalAlarmCount =jsonObject.getString("totalAlarmCount");//报警总数
                String yawCount =jsonObject.getString("yawCount");//报警总数
                String date =jsonObject.getString("date");//时间
                String vehicleName = tDisVehicleMapper.selectByVid(vId);
                jsonObject.put("vehicleName", vehicleName);
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(vehicleName);
                row3.createCell(1).setCellValue(overspeedCount);
                row3.createCell(2).setCellValue(fatigueDrivingCount);
                row3.createCell(3).setCellValue(forbidOutCount);
                row3.createCell(4).setCellValue(forbidInCount);
                row3.createCell(5).setCellValue(emergencyCount);
                row3.createCell(6).setCellValue(nightDrivingCount);
                row3.createCell(7).setCellValue(yawCount);
                row3.createCell(8).setCellValue(totalAlarmCount);
                row3.createCell(9).setCellValue(date);
            }
            String fileName="报警统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "业户报警统计导出按钮")
    @RequestMapping(value = "/businessAlarmStatisticsExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getBusinessAlarmStatisticsExcelOut(String startDate,String endDate,String eid,String regionCode,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("业户报警统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("业户报警统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("业户名称");
            row2.createCell(1).setCellValue("所属区域");
            row2.createCell(2).setCellValue("所属行业");
            row2.createCell(3).setCellValue("超速报警");
            row2.createCell(4).setCellValue("疲劳报警");
            row2.createCell(5).setCellValue("禁入报警");
            row2.createCell(6).setCellValue("禁出报警");
            row2.createCell(7).setCellValue("紧急报警");
            row2.createCell(8).setCellValue("夜间禁行");
            row2.createCell(9).setCellValue("偏航报警");
            row2.createCell(10).setCellValue("报警总数");
            row2.createCell(11).setCellValue("日期");
            Map map=new HashMap();
            map.put("startDate",startDate);//必传 开始查询时间yyyy-MM-dd
            map.put("endDate",endDate);//必传 结束查询时间yyyy-MM-dd，不要跨年
            map.put("eIds",eid);//企业id,多个id以逗号分隔
            map.put("regionCode",regionCode);//必传 用户行政区划编码
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str).equals("null")|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/alarmType/enterprise";
            String result= HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String overspeedCount=jsonObject.getString("overspeedCount");//超速报警
                String fatigueDrivingCount=jsonObject.getString("fatigueDrivingCount");//疲劳报警
                String forbidInCount=jsonObject.getString("forbidInCount");//禁入报警
                String forbidOutCount=jsonObject.getString("forbidOutCount");//禁出报警
                String emergencyCount=jsonObject.getString("emergencyCount");//禁出报警
                String nightDrivingCount=jsonObject.getString("nightDrivingCount");//夜间禁行
                String yawCount=jsonObject.getString("yawCount");//偏航报警
                String totalVehicle=jsonObject.getString("totalAlarmCount");//报警总数
                String date=jsonObject.getString("date");//日期
                //List<Map<String,Object>>enterprise=sysEnterpriseMapper.selectByeId(eId);//企业名称和所属地区
                List<Map<String,Object>>enterprise=tDisEnterpriseMapper.selectByEidList(eId);
                String industry = "";
                Integer areaCode = null;
                String enterpriseName = "";//企业名称
                if (enterprise.size()>0){
                     industry = String.valueOf(enterprise.get(0).get("industry"));
                     areaCode = Integer.parseInt(String.valueOf(enterprise.get(0).get("area_code")));
                     enterpriseName = String.valueOf(enterprise.get(0).get("enterprise"));//企业名称
                }else {
                     industry ="";
                     areaCode = null;
                     enterpriseName = "";//企业名称
                }

                    String areaCodeName = tRegionMapper.selectAreaCode(areaCode);//所属地区
                    String industryId = industry;
                    String IndustryName = disDictionaryMapper.selectByItemValue(industryId);//所属行业
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(areaCodeName);
                row3.createCell(2).setCellValue(IndustryName);
                row3.createCell(3).setCellValue(overspeedCount);
                row3.createCell(4).setCellValue(fatigueDrivingCount);
                row3.createCell(5).setCellValue(forbidInCount);
                row3.createCell(6).setCellValue(forbidOutCount);
                row3.createCell(7).setCellValue(emergencyCount);
                row3.createCell(8).setCellValue(nightDrivingCount);
                row3.createCell(9).setCellValue(yawCount);
                row3.createCell(10).setCellValue(totalVehicle);
                row3.createCell(11).setCellValue(date);
            }
            String fileName="业户报警统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
            }catch (Exception e){
         e.printStackTrace();
        }
    }

    @ApiOperation(value = "行业报警导出按钮")
    @RequestMapping(value = "/industryAlarmStatisticsExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getIndustryAlarmStatisticsExcelOut(String startDate,String endDate,String industryId,String regionCode,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("行业报警统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("行业报警统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("所属行业");
            row2.createCell(1).setCellValue("车辆总数");
            row2.createCell(2).setCellValue("入网车辆总数");
            row2.createCell(3).setCellValue("超速报警");
            row2.createCell(4).setCellValue("疲劳报警");
            row2.createCell(5).setCellValue("禁入报警");
            row2.createCell(6).setCellValue("禁出报警");
            row2.createCell(7).setCellValue("紧急报警");
            row2.createCell(8).setCellValue("夜间禁行");
            row2.createCell(9).setCellValue("偏航报警");
            row2.createCell(10).setCellValue("报警总数");
            row2.createCell(11).setCellValue("日期");
            Map map=new HashMap();
            map.put("startDate",startDate);//必传 查询时间yyyy-MM-dd
            map.put("endDate",endDate);//必传 结束时间yyyy-MM-dd
            map.put("industryId",industryId);//行业id
            map.put("regionCode",regionCode);//必传 用户行政区划编码
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) .equals("null")|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/alarmType/industry";
            String result= HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                String industry=jsonObject.getString("industryId");//行业id
                String totalVehicle=jsonObject.getString("totalVehicle");//车辆总数
                String netVehicle=jsonObject.getString("netVehicle");//入网车辆总数
                String overspeedCount=jsonObject.getString("overspeedCount");//超速报警
                String fatigueDrivingCount=jsonObject.getString("fatigueDrivingCount");//疲劳报警
                String forbidInCount=jsonObject.getString("forbidInCount");//禁入报警
                String forbidOutCount=jsonObject.getString("forbidOutCount");//禁出报警
                String emergencyCount=jsonObject.getString("emergencyCount");//紧急报警
                String nightDrivingCount=jsonObject.getString("nightDrivingCount");//夜间报警
                String yawCount=jsonObject.getString("yawCount");//偏航驾驶
                String totalAlarmCount=jsonObject.getString("totalAlarmCount");//报警总数
                String date=jsonObject.getString("date");//日期
                String industryTypeId=industry;
                String industryName=disDictionaryMapper.selectIndustryId(industryTypeId);
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(industryName);
                row3.createCell(1).setCellValue(totalVehicle);
                row3.createCell(2).setCellValue(netVehicle);
                row3.createCell(3).setCellValue(overspeedCount);
                row3.createCell(4).setCellValue(fatigueDrivingCount);
                row3.createCell(5).setCellValue(forbidInCount);
                row3.createCell(6).setCellValue(forbidOutCount);
                row3.createCell(7).setCellValue(emergencyCount);
                row3.createCell(8).setCellValue(nightDrivingCount);
                row3.createCell(9).setCellValue(yawCount);
                row3.createCell(10).setCellValue(totalAlarmCount);
                row3.createCell(11).setCellValue(date);
            }
            String fileName="行业报警统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
    }catch (Exception e){
        e.printStackTrace();}
    }


    @ApiOperation(value = "地区报警统计导出按钮")
    @RequestMapping(value = "/AreaAlarmStatisticsExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getAreaAlarmStatistics(String startDate,String endDate,String regionCode,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("地区报警统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("地区报警统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("所属地区");
            row2.createCell(1).setCellValue("车辆总数");
            row2.createCell(2).setCellValue("入网车辆总数");
            row2.createCell(3).setCellValue("超速报警");
            row2.createCell(4).setCellValue("疲劳驾驶");
            row2.createCell(5).setCellValue("禁入报警");
            row2.createCell(6).setCellValue("禁出报警");
            row2.createCell(7).setCellValue("紧急报警");
            row2.createCell(8).setCellValue("夜间禁行");
            row2.createCell(9).setCellValue("偏航报警");
            row2.createCell(10).setCellValue("报警总数");
            row2.createCell(11).setCellValue("日期");
        Map map=new HashMap();
        map.put("startDate",startDate);//必传 查询时间yyyy-MM-dd
        map.put("endDate",endDate);//必传 结束时间yyyy-MM-dd
        map.put("admdivcode",regionCode);//必传 所属区划

        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/alarmType/region";
        String result= HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer admdivCode=Integer.parseInt(jsonObject.getString("admdivcode"));//地区名
            String totalVehicle=jsonObject.getString("totalVehicle");//车辆总数
            String netVehicle=jsonObject.getString("netVehicle");//入网车辆总数
            String overspeedCount=jsonObject.getString("overspeedCount");//超速报警
            String fatigueDrivingCount=jsonObject.getString("fatigueDrivingCount");//疲劳驾驶
            String forbidInCount=jsonObject.getString("forbidInCount");//禁入报警
            String forbidOutCount=jsonObject.getString("forbidOutCount");//禁出报警
            String emergencyCount=jsonObject.getString("emergencyCount");//紧急报警
            String nightDrivingCount=jsonObject.getString("nightDrivingCount");//夜间进行
            String yawCount=jsonObject.getString("yawCount");//偏航报警
            String totalAlarmCount=jsonObject.getString("totalAlarmCount");//报警总数
            String date=jsonObject.getString("date");//报警总数
            String areaCodeName=tRegionMapper.selectAreaCode(admdivCode);//所属地区

            //在sheet里创建第三行
            XSSFRow row3=sheet.createRow(i+2);
            row3.createCell(0).setCellValue(areaCodeName);
            row3.createCell(1).setCellValue(totalVehicle);
            row3.createCell(2).setCellValue(netVehicle);
            row3.createCell(3).setCellValue(overspeedCount);
            row3.createCell(4).setCellValue(fatigueDrivingCount);
            row3.createCell(5).setCellValue(forbidInCount);
            row3.createCell(6).setCellValue(forbidOutCount);
            row3.createCell(7).setCellValue(emergencyCount);
            row3.createCell(8).setCellValue(nightDrivingCount);
            row3.createCell(9).setCellValue(yawCount);
            row3.createCell(10).setCellValue(totalAlarmCount);
            row3.createCell(11).setCellValue(date);
        }

            String fileName="地区报警统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
    }catch (Exception e){
        e.printStackTrace();}
    }


    @ApiOperation(value = "无运政导出按钮")
    @RequestMapping(value = "/nonTransportExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getNonTransportExcelOut(String pName,String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("无运政车辆统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("无运政车辆统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号");
            row2.createCell(1).setCellValue("车辆颜色");
            row2.createCell(2).setCellValue("企业名称");
            row2.createCell(3).setCellValue("平台名称");
            row2.createCell(4).setCellValue("在线状态");
            row2.createCell(5).setCellValue("首次上线时间");
            row2.createCell(6).setCellValue("末次上线时间");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar nowTime = Calendar.getInstance();
            nowTime.add(Calendar.MINUTE, -5);
            String onlineTime=sdf.format(nowTime.getTime());//在线时间:当前时间前五分钟之内
            List<Map<String,Object>>mismatchVehicle=new LinkedList<>();
            List<Map> pIdsList=new ArrayList<>();
            if (pIdsList.size()>0){
                for (int j = 0; j < pIdsList.size(); j++) {
                    Integer pId=Integer.valueOf(String.valueOf(pIdsList.get(j).get("platform_id")));
                    mismatchVehicle=disMismatchVehicleMapper.selectPage(pId,vNumber,1,100000);
                }
            }else {
                mismatchVehicle=disMismatchVehicleMapper.selectPage(null,vNumber,1,100000);
            }

            for (int i = 0; i < mismatchVehicle.size(); i++) {
                Map map=mismatchVehicle.get(i);
                String online= String.valueOf(map.get("updateDate"));
                if (online.equals("null")){
                    map.put("onlineStatus","离线");
                    online="1979-01-01 00:00:00";
                }
                if (sdf.parse(onlineTime).before(sdf.parse(online))){
                    map.put("onlineStatus","在线");
                }else {
                    map.put("onlineStatus","离线");
                }
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(String.valueOf(map.get("vehicleNumber")));
                row3.createCell(1).setCellValue(String.valueOf(map.get("vehicleLicenseColor")));
                row3.createCell(2).setCellValue(String.valueOf(map.get("enterpriseName")));
                row3.createCell(3).setCellValue(String.valueOf(map.get("platformName")));
                row3.createCell(4).setCellValue(String.valueOf(map.get("onlineStatus")));
                row3.createCell(5).setCellValue(String.valueOf(map.get("createDate")));
                row3.createCell(6).setCellValue(String.valueOf(map.get("updateDate")));
            }

            String fileName="无运政车辆统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "车辆上线统计导出按钮")
    @RequestMapping(value = "/onlineExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getOnlineExcelOut(EncapsulationTired encapsulationTired, String eid, String pName, String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("车辆上线统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆上线统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("企业名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("车牌颜色");
            row2.createCell(4).setCellValue("车辆状态");
            row2.createCell(5).setCellValue("开始时间");
            row2.createCell(6).setCellValue("结束时间");
            String pIdList="";
            String pIds=null;
            if (pName!=null&& pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (eid==null ||eid.equals("")||eid.equals("null")){
                eid=null;
            }
            Map map=new HashMap();
            if (vNumber.equals("null")){
                vNumber=null;
            }
            encapsulationTired.setVnumber(vNumber);
            encapsulationTired.setEnterpriseIds(eid);
            encapsulationTired.setPlatformIds(pIds);
            String path="/dis/v1/track/statistics";
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            JSONObject jsonString = new JSONObject();
            String body= jsonString.toJSONString(encapsulationTired);
            String result=HttpClientUtils.doPostTestThree(path,headMap,map,body);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            if (jo==null){
                log.info(String.valueOf(json));
                return;
            }
            JSONArray jsonArray=jo.getJSONArray("list");
            if (jsonArray==null){
                log.info(String.valueOf(json));
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vehicelId=Integer.parseInt(jsonObject.getString("vehicleId"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("enterpriseId"));//企业id
                Integer pId=Integer.parseInt(jsonObject.getString("platformId"));//平台id
                String start=jsonObject.getString("startTime");//开始时间
                String end=jsonObject.getString("endTime");//结束时间
                List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vehicelId);
                String vehicleColor=tDisVehicleMapper.selectVehicleColor(vehicelId);
                String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicleColor);
                String onlineStatus="";
                if (String.valueOf(map.get("onlineStatus")).equals("0")){
                     onlineStatus="在线";
                }else {
                    onlineStatus="离线";
                }
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                if (vehicleList.size()>0){
                    row3.createCell(0).setCellValue(String.valueOf(vehicleList.get(0).get("enterpriseName")));
                    row3.createCell(1).setCellValue(String.valueOf(vehicleList.get(0).get("platformName")));
                }else {
                    row3.createCell(0).setCellValue("");
                    row3.createCell(1).setCellValue("");
                }

                row3.createCell(2).setCellValue(String.valueOf(jsonObject.getString("vnumber")));
                row3.createCell(3).setCellValue(vehicleLicenseColor);
                row3.createCell(4).setCellValue(onlineStatus);
                row3.createCell(5).setCellValue(start);
                row3.createCell(6).setCellValue(end);
            }

            String fileName="车辆上线统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }

    @ApiOperation(value = "车辆漂移次数统计导出按钮")
    @RequestMapping(value = "/statisticsOfVehicleTrajectoryDriftTimesExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getStatisticsOfVehicleTrajectoryDriftTimesExcelOut(String startTime,String endTime,String regionCode,String eid,String pName,String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("车辆漂移次数统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆漂移次数统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("业户名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("经度");
            row2.createCell(4).setCellValue("纬度");
            row2.createCell(5).setCellValue("漂移位置");
            row2.createCell(6).setCellValue("时间");
            String vIdlist="";
            String pIdList="";
            String vIds=null;
            String pIds=null;
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (pName!=null&& pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (eid==null ||eid.equals("")||eid.equals("null")){
                eid=null;
            }
            Map map=new HashMap();
            map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd HH:mm:ss
            map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd HH:mm:ss,查询时间不要超过30天
            map.put("pIds",pIds);//平台id,多个id英文逗号分隔
            map.put("regionCode",regionCode);
            map.put("eIds",eid);//企业id,多个id英文逗号分隔
            map.put("vIds",vIds);//车辆id,多个id英文逗号分隔
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleDrift/info";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            if (json==null){
                log.info(String.valueOf(json));
                return;
            }
            //JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=json.getJSONArray("result");

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String lng=jsonObject.getString("lng");//经度
                String lat=jsonObject.getString("lat");//纬度
                String driftingLocalhost=null;
      /*          String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                String platformName=tDisPlatformMapper.selectpId(pId);*/
                List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
                String enterpriseName="";
                String platformName="";
                String vehicleNumber="";
                if (vehicleList.size()>0){
                    enterpriseName=String.valueOf(vehicleList.get(0).get("enterpriseName"));
                    platformName=String.valueOf(vehicleList.get(0).get("platformName"));
                    vehicleNumber=String.valueOf(vehicleList.get(0).get("vehicleNumber"));
                }else {
                    enterpriseName="";
                    platformName="";
                    vehicleNumber="";
                }
                jsonObject.put("driftingLocalhost",driftingLocalhost);
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(platformName);
                row3.createCell(2).setCellValue(vehicleNumber);
                row3.createCell(3).setCellValue(String.valueOf(jsonObject.get("lng")));
                row3.createCell(4).setCellValue(String.valueOf(jsonObject.get("lat")));
                row3.createCell(5).setCellValue(String.valueOf(jsonObject.get("address")));
                row3.createCell(6).setCellValue(String.valueOf(jsonObject.get("ts")));

            }

            String fileName="车辆漂移次数统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }

    @ApiOperation(value = "车辆报警统计导出按钮")
    @RequestMapping(value = "/vehicleAlarmStatisticExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getVehicleAlarmStatisticExcelOut(String startTime,String endTime,String eid,String pName,String vNumber,String regionCode,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("车辆报警统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆报警统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("企业名称");
            row2.createCell(1).setCellValue("平台名称");
            row2.createCell(2).setCellValue("车牌号");
            row2.createCell(3).setCellValue("车牌颜色");
            row2.createCell(4).setCellValue("报警原因");
            row2.createCell(5).setCellValue("报警时间");
            String eIdsList="";
            String vIdlist="";
            String pIdList="";
            String vIds=null;
            String pIds=null;
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (eid==null ||eid.equals("")||eid.equals("null")){
                eid=null;
            }
            if (pName!=null && pName.equals("")==false){
                List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


                if (pIdsList.size()>0){
                    for (int i = 0; i < pIdsList.size(); i++) {
                        pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                    }
                    pIds=StringUtils.join(pIdList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map=new HashMap();
            map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd HH:mm:ss
            map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd HH:mm:ss
            map.put("pIds",pIds);//平台id,多个英文逗号分隔
            map.put("regionCode",regionCode);
            map.put("eIds",eid);//企业id,多个英文逗号分隔
            map.put("vIds",vIds);//车辆id,多个英文逗号分隔
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) .equals("null")|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleAlarmStatistic/info";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String alarmType=jsonObject.getString("alarmType");//报警原因
                String vehicelColor=jsonObject.getString("vehicleLicenseColor");//车辆颜色
                String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicelColor);//车牌颜色
                String alarmTypeName=disDictionaryMapper.selectAlarmType(alarmType);
                List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
                String enterpriseName="";
                String platformName="";
                String vehicleNumber="";
                if (vehicleList.size()>0){
                    enterpriseName= String.valueOf(vehicleList.get(0).get("enterpriseName"));
                    platformName= String.valueOf(vehicleList.get(0).get("platformName"));
                    vehicleNumber= String.valueOf(vehicleList.get(0).get("vehicleNumber"));
                }else {
                    enterpriseName= "";
                    platformName= "";
                    vehicleNumber= "";
                }
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseName);
                row3.createCell(1).setCellValue(platformName);
                row3.createCell(2).setCellValue(vehicleNumber);
                row3.createCell(3).setCellValue(vehicleLicenseColor);
                row3.createCell(4).setCellValue(alarmType);
                row3.createCell(5).setCellValue(String.valueOf(jsonObject.get("startTime")));

            }

            String fileName="车辆报警统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "入域车辆统计导出按钮")
    @RequestMapping(value = "/inTheDomainOfVehicleExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getInTheDomainOfVehicleExcelOut(String industryId,String admdivcode,String eName,String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("入域车辆统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("入域车辆统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("所属行业");
            row2.createCell(3).setCellValue("业户名称");
            row2.createCell(4).setCellValue("最后上线时间");
            row2.createCell(5).setCellValue("当前地区");
            String eIdsList="";
            String vIdlist="";
            String eIds=null;
            String vIds=null;
            if (eName!=null && eName.equals("")==false){
                List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
                if (eIdsLists.size()>0){
                    for (int i = 0; i < eIdsLists.size(); i++) {
                        eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                    }
                    eIds=StringUtils.join(eIdsList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map=new HashMap();
            map.put("industryId",industryId);//行业编码
            map.put("vid",vIds);//车辆ID
            map.put("eid",eIds);//企业ID
            map.put("admdivcode",admdivcode);//地区编码
            map.put("currPage","1");//必传 页码
            map.put("pageSize","10000");//必传 页数
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/statistic/InOrOut/in";
            String result=HttpClientUtils.doPost(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            if (jsonArray.size()==0){
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(2);
                row3.createCell(0).setCellValue("");
                row3.createCell(1).setCellValue("");
                row3.createCell(2).setCellValue("");
                row3.createCell(3).setCellValue("");
                row3.createCell(4).setCellValue("");
                row3.createCell(5).setCellValue("");
            }else {
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jsonObject=jsonArray.getJSONObject(i);
                    Integer vId=Integer.parseInt(jsonObject.getString("vid"));//车辆id
                    Integer eId=Integer.parseInt(jsonObject.getString("eid"));//企业id
                    String oId=jsonObject.getString("admdivcode");//机构id
                    String areaCode=tRegionMapper.selectByoId(Integer.valueOf(oId));
                    String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                    String vehicleName=tDisVehicleMapper.selectByVid(vId);
                    jsonObject.put("enterpriseName",enterpriseName);
                    jsonObject.put("vehicleName",vehicleName);
                    jsonObject.put("administrationName",areaCode);
                    //在sheet里创建第三行
                    XSSFRow row3=sheet.createRow(i+2);
                    row3.createCell(0).setCellValue(String.valueOf(vehicleName));
                    row3.createCell(1).setCellValue(String.valueOf(jsonObject.get("colorName")));
                    row3.createCell(2).setCellValue(String.valueOf(jsonObject.get("industryName")));
                    row3.createCell(3).setCellValue(enterpriseName);
                    row3.createCell(4).setCellValue(String.valueOf(jsonObject.get("ts")));
                    row3.createCell(5).setCellValue(String.valueOf(jsonObject.get("admdivcodeName")));
                }
            }
            String fileName="入域车辆统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "出域车辆统计导出按钮")
    @RequestMapping(value = "/theDomainOfVehicleExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getTheDomainOfVehicleExcelOut(String industryId,String admdivcode,String eName,String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("出域车辆统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("出域车辆统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("所属行业");
            row2.createCell(3).setCellValue("业户名称");
            row2.createCell(4).setCellValue("最后上线时间");
            row2.createCell(5).setCellValue("当前地区");
            String eIdsList="";
            String vIdlist="";
            String eIds=null;
            String vIds=null;
            if (eName!=null && eName.equals("")==false){
                List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
                if (eIdsLists.size()>0){
                    for (int i = 0; i < eIdsLists.size(); i++) {
                        eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                    }
                    eIds=StringUtils.join(eIdsList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map=new HashMap();
            map.put("industryId",industryId);//行业编码
            map.put("vid",vIds);//车辆ID
            map.put("eid",eIds);//企业ID
            map.put("admdivcode",admdivcode);//必传 地区编码
            map.put("currPage","1");//必传 页码
            map.put("pageSize","10000");//必传 页数
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/statistic/InOrOut/out";
            String result=HttpClientUtils.doPost(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vid"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("eid"));//企业id
                String oId=jsonObject.getString("admdivcode");//机构id
                String areaCode=tRegionMapper.selectByoId(Integer.valueOf(oId));
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                String vehicleName=tDisVehicleMapper.selectByVid(vId);
                jsonObject.put("enterpriseName",enterpriseName);
                jsonObject.put("vehicleName",vehicleName);
                jsonObject.put("administrationName",areaCode);
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(String.valueOf(vehicleName));
                row3.createCell(1).setCellValue(String.valueOf(jsonObject.get("colorName")));
                row3.createCell(2).setCellValue(String.valueOf(jsonObject.get("industryName")));
                row3.createCell(3).setCellValue(enterpriseName);
                row3.createCell(4).setCellValue(String.valueOf(jsonObject.get("ts")));
                row3.createCell(5).setCellValue(String.valueOf(jsonObject.get("admdivcodeName")));

            }

            String fileName="出域车辆统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "用户操作记录导出按钮")
    @RequestMapping(value = "/logExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getLogExcelOut(HttpServletRequest request,HttpServletResponse response,String userName, String operation, String startTime,String endTime){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("用户操作记录表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFCellStyle style =wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("用户操作记录表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("用户名称");
            row2.createCell(1).setCellValue("操作类型");
            row2.createCell(2).setCellValue("操作IP");
            row2.createCell(3).setCellValue("操作时间");
            List<Map<String,Object>> selectCondition=sysLogService.selectCondition(userName,operation,startTime,endTime);
            for (int i = 0; i < selectCondition.size(); i++) {
                Map map=selectCondition.get(i);
                String name= String.valueOf(map.get("userName"));
                String operations= String.valueOf(map.get("operation"));
                String ip= String.valueOf(map.get("ip"));
                String createdate= String.valueOf(map.get("createdate"));
                //在sheet里创建第三行
                HSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(name);
                row3.createCell(1).setCellValue(operations);
                row3.createCell(2).setCellValue(ip);
                row3.createCell(3).setCellValue(createdate);

            }
            String fileName="用户操作记录表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }



    @ApiOperation(value = "接入业户管理导出按钮")
    @RequestMapping(value = "/joinEnterpriseExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getJoinEnterpriseExcelOut(Integer regionCode,Integer level,String enterpriseName,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("接入业户表");
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("接入业户表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("业户名称");
            row2.createCell(1).setCellValue("所属地区");
            row2.createCell(2).setCellValue("所属行业");
            row2.createCell(3).setCellValue("管辖机构");
            row2.createCell(4).setCellValue("经营状态");
            row2.createCell(5).setCellValue("经营范围");
            row2.createCell(6).setCellValue("平台名称");

/*            Integer areaCode=null;
            if (level==1){
                areaCode= Integer.valueOf(String.valueOf(regionCode).substring(0,2));
            }else if (level==2){
                areaCode= Integer.valueOf(String.valueOf(regionCode).substring(0,4));
            }else if (level==3){
                areaCode= regionCode;
            }
            if (enterpriseName.equals("null")){
                enterpriseName=null;
            }*/
            List<Map<String,Object>> enterpriseList=tDisEnterpriseMapper.selectAll(enterpriseName);
            for (int i = 0; i < enterpriseList.size(); i++) {
                Map map=enterpriseList.get(i);
                Integer areaCodeName=Integer.parseInt(String.valueOf(map.get("regionCode")));
                String code=tRegionMapper.selectAreaCode(areaCodeName);
                if (code==null){
                    code="";
                }
                String industry=String.valueOf(map.get("industryId"));
                String industryName=tDisDictionaryMapper.selectIndustryId(industry);
                if (industryName==null){
                    industryName="";
                }
                String enterpriseNames=String.valueOf(map.get("enterpriseName"));
                if (enterpriseNames.equals("null")){
                    enterpriseNames="";
                }
                String administrationOrgniaztion= String.valueOf(map.get("administrationOrgniaztion"));
                if (administrationOrgniaztion.equals("null")){
                    administrationOrgniaztion="";
                }
                String managementForms= String.valueOf(map.get("managementForms"));
                if (managementForms.equals("null")){
                    managementForms="";
                }
                String scope= String.valueOf(map.get("scope"));
                if (scope.equals("null")){
                    scope="";
                }
                String platformName= String.valueOf(map.get("platformName"));
                if (platformName.equals("null")){
                    platformName="";
                }
                //在sheet里创建第三行
                HSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseNames);//业户名称
                row3.createCell(1).setCellValue(code);//所属地区
                row3.createCell(2).setCellValue(industryName);
                row3.createCell(3).setCellValue(administrationOrgniaztion);
                row3.createCell(4).setCellValue(managementForms);
                row3.createCell(5).setCellValue(scope);
                row3.createCell(6).setCellValue(platformName);
            }
            String fileName="接入业户表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "接入车辆导出")
    @RequestMapping(value = "/joinVehcielExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getJoinVehicleExcelOut(Integer platformId, String vehicleNumber, String vehicleType, String enterpriseName, Integer networkState,
                                   Short vehicleLicenseColor, Integer areaCode,Integer level,HttpServletRequest request,HttpServletResponse response)  {
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("接入车辆表");
            XSSFCellStyle style =wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("接入车辆表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("车辆属地关系机构名称");
            row2.createCell(3).setCellValue("所属行业");
            row2.createCell(4).setCellValue("所属地区");
            row2.createCell(5).setCellValue("车辆类型");
            row2.createCell(6).setCellValue("业户名称");
            row2.createCell(7).setCellValue("平台名称");
            row2.createCell(8).setCellValue("入网状态");
            row2.createCell(9).setCellValue("在线状态");
            String onlineStatus="";
            Integer vehicleTypeNumber=null;
            if (vehicleType.equals("null")){
                vehicleTypeNumber=0;
            }else {
                vehicleTypeNumber= Integer.valueOf(vehicleType);
            }
            if (vehicleNumber.equals("null")){
                vehicleNumber="";
            }
            if (enterpriseName.equals("null")){
                enterpriseName="";
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date=new Date();
           /* Integer regionCode=null;
            if (level==1){
                regionCode= Integer.valueOf(String.valueOf(areaCode).substring(0,2));
            }else if (level==2){
                regionCode= Integer.valueOf(String.valueOf(areaCode).substring(0,4));
            }else if (level==3){
                regionCode= areaCode;
            }*/
            List<Map<String,Object>> vehicle=disVehicleMapper.selectJoinVehicle(platformId,vehicleNumber,vehicleTypeNumber,enterpriseName,networkState,vehicleLicenseColor);
            for (int i = 0; i < vehicle.size(); i++) {
                Map map=vehicle.get(i);
                String industry=String.valueOf(map.get("industry"));
                String licenseColor=String.valueOf(map.get("vehicleLicenseColor"));
                String vehicleTypeCode=String.valueOf(map.get("vehicleType"));
                String regionCodeId=String.valueOf(map.get("regionCode"));
                String updateDate= String.valueOf(map.get("updateDate"));
                if (updateDate.equals("null")){
                    onlineStatus="离线";
                }else {
                    Date onlineDate=simpleDateFormat.parse(updateDate);
                    if (DateUtils.isSameDay(date,onlineDate)==true){
                        onlineStatus="在线";
                    }else {
                        onlineStatus="离线";
                    }
                }
                //字典表查询行业,车牌颜色
                String vehicleTypeName=disDictionaryMapper.selectVehicleType(vehicleTypeCode);
                if (vehicleTypeName.equals("null")){
                    vehicleTypeName="";
                }
                String industryName=disDictionaryMapper.selectIndustryId(industry);
                if (industryName.equals("null")){
                    industryName="";
                }
                String license=disDictionaryMapper.selectVehicleColor(licenseColor);
                if (license.equals("null")){
                    license="";
                }
                String regionCodeName=tRegionMapper.selectAreaCode(Integer.valueOf(regionCodeId));
                if (regionCodeName.equals("null")){
                    regionCodeName="";
                }
                String enterpriseNames=String.valueOf(map.get("enterpriseName"));
                if (enterpriseNames.equals("null")){
                    enterpriseNames="";
                }
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(String.valueOf(map.get("vehicleNumber")));
                row3.createCell(1).setCellValue(license);
                row3.createCell(2).setCellValue(String.valueOf(map.get("administrationOrgniaztionName")));
                row3.createCell(3).setCellValue(industryName);
                row3.createCell(4).setCellValue(regionCodeName);
                row3.createCell(5).setCellValue(vehicleTypeName);
                row3.createCell(6).setCellValue(enterpriseNames);
                row3.createCell(7).setCellValue(String.valueOf(map.get("platformName")));
                row3.createCell(8).setCellValue(String.valueOf(map.get("networkState")));
                row3.createCell(9).setCellValue(onlineStatus);
            }
            String fileName="接入车辆表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }


    @ApiOperation(value = "车辆导出")
    @RequestMapping(value = "/vehcielExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getVehicleExcelOut(Integer platformId, String vehicleNumber, String vehicleType, String enterpriseName, Integer networkState,
                                   Short vehicleLicenseColor, Integer areaCode,Integer level,HttpServletRequest request,HttpServletResponse response)  {
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            XSSFWorkbook wb = new XSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            XSSFSheet sheet = wb.createSheet("车辆表");
            XSSFCellStyle style =wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            XSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            XSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("车辆表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            XSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("车辆属地关系机构名称");
            row2.createCell(3).setCellValue("所属行业");
            row2.createCell(4).setCellValue("所属地区");
            row2.createCell(5).setCellValue("车辆类型");
            row2.createCell(6).setCellValue("业户名称");
            row2.createCell(7).setCellValue("入网状态");
            String onlineStatus="";
            Integer vehicleTypeNumber=null;
            if (vehicleType.equals("null")){
                vehicleTypeNumber=0;
            }else {
                vehicleTypeNumber= Integer.valueOf(vehicleType);
            }
            if (vehicleNumber.equals("null")){
                vehicleNumber="";
            }
            if (enterpriseName.equals("null")){
                enterpriseName="";
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date=new Date();
/*            Integer regionCode=null;
            if (level==1){
                regionCode= Integer.valueOf(String.valueOf(areaCode).substring(0,2));
            }else if (level==2){
                regionCode= Integer.valueOf(String.valueOf(areaCode).substring(0,4));
            }else if (level==3){
                regionCode= areaCode;
            }*/
            List<Map<String,Object>> vehicle=disVehicleMapper.selectJoinVehicle(platformId,vehicleNumber,vehicleTypeNumber,enterpriseName,networkState,vehicleLicenseColor);
            for (int i = 0; i < vehicle.size(); i++) {
                Map map=vehicle.get(i);
                String industry=String.valueOf(map.get("industry"));
                String licenseColor=String.valueOf(map.get("vehicleLicenseColor"));
                String vehicleTypeCode=String.valueOf(map.get("vehicleType"));
                String regionCodeId=String.valueOf(map.get("regionCode"));
                String updateDate= String.valueOf(map.get("updateDate"));
                if (updateDate.equals("null")){
                    onlineStatus="离线";
                }else {
                    Date onlineDate=simpleDateFormat.parse(updateDate);
                    if (DateUtils.isSameDay(date,onlineDate)==true){
                        onlineStatus="在线";
                    }else {
                        onlineStatus="离线";
                    }
                }
                //字典表查询行业,车牌颜色
                String vehicleTypeName=disDictionaryMapper.selectVehicleType(vehicleTypeCode);
                String industryName=disDictionaryMapper.selectIndustryId(industry);
                String license=disDictionaryMapper.selectVehicleColor(licenseColor);
                String regionCodeName=tRegionMapper.selectAreaCode(Integer.valueOf(regionCodeId));
                //在sheet里创建第三行
                XSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(String.valueOf(map.get("vehicleNumber")));
                row3.createCell(1).setCellValue(license);
                row3.createCell(2).setCellValue(String.valueOf(map.get("administrationOrgniaztionName")));
                row3.createCell(3).setCellValue(industryName);
                row3.createCell(4).setCellValue(regionCodeName);
                row3.createCell(5).setCellValue(vehicleTypeName);
                row3.createCell(6).setCellValue(String.valueOf(map.get("enterpriseName")));
                row3.createCell(7).setCellValue(String.valueOf(map.get("networkState")));
            }
            String fileName="车辆表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }


    @ApiOperation(value = "报警超时推送导出按钮")
    @RequestMapping(value = "/alarmTimeoutExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getAlarmTimeoutExcelOut(String date,String vNumber,String eName,String regionCode,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("报警超时推送表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("报警超时推送表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("车辆属地管辖机构名称");
            row2.createCell(3).setCellValue("所属行业");
            row2.createCell(4).setCellValue("所属地区");
            row2.createCell(5).setCellValue("车辆类型");
            row2.createCell(6).setCellValue("所属企业");
            row2.createCell(7).setCellValue("报警类型");
            row2.createCell(8).setCellValue("报警时长（m）");
            row2.createCell(9).setCellValue("日期");
            String eIdsList = "";
            String vIdlist = "";
            String eIds = null;
            String vIds = null;
            if (eName != null && eName.equals("") == false) {
                List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
                if (eIdsLists.size() > 0) {
                    for (int i = 0; i < eIdsLists.size(); i++) {
                        eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id") + ",";
                    }
                    eIds = StringUtils.join(eIdsList.split(","), ",");
                } else {
                    String list = "{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);

                }
            }
            if (vNumber != null && vNumber.equals("") == false) {
                List<Map> vehicleNumberList = tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size() > 0) {
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist = vIdlist + vehicleNumberList.get(i).get("vehicle_id") + ",";
                    }
                    vIds = StringUtils.join(vIdlist.split(","), ",");
                } else {
                    String list = "{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map = new HashMap();
            map.put("date", date);//必选 查询时间yyyy-MM-dd
            map.put("vIds", vIds);//车辆id，多个英文逗号分隔
            map.put("eIds", eIds);//企业id，多个英文逗号分隔
            map.put("regionCode", regionCode);
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if (map.get(str) == null || map.get(str) == "null" || map.get(str) == "") {
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String, String> headMap = new HashMap<>();
            headMap.put("clientCode", clientCode);
            String url = "http://" + Ip + ":" + port + "/dis/statistics/vehicleAlarm/overtimePush";
            String result = HttpClientUtils.doGet(url, headMap, map);
            JSONObject json = JSONObject.parseObject(result);
            JSONObject jo = json.getJSONObject("result");
            JSONArray jsonArray = jo.getJSONArray("list");
            if (jsonArray == null) {
                log.info(String.valueOf(json));
            }
            for (int i = 0; i < jsonArray.size(); i++) {

                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String industryId=jsonObject.getString("industryId");//行业id
                String alarmType=jsonObject.getString("alarmType");//报警类型
                String industryName= tDisDictionaryMapper.selectByItemValue(industryId);
                String oId=jsonObject.getString("oId");//机构id
                String administrationName=tRegionMapper.selectByoId(Integer.parseInt(oId));
                String regionName=tRegionMapper.selectAreaCode(Integer.parseInt(oId));
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);//企业名称
                List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectVehicle(vId);//车辆名称
                String alarmTypeName=tDisDictionaryMapper.selectAlarmType(alarmType);
                String vehicleType="";

                //在sheet里创建第三行
                HSSFRow row3 = sheet.createRow(i + 2);
                if (vehicleList.size()==0){
                    row3.createCell(0).setCellValue("null");
                    row3.createCell(1).setCellValue("null");
                }else {
                    row3.createCell(0).setCellValue(String.valueOf(vehicleList.get(0).get("vehicle_number")));
                    row3.createCell(1).setCellValue(String.valueOf(vehicleList.get(0).get("item_name")));
                }
                row3.createCell(2).setCellValue(administrationName);
                row3.createCell(3).setCellValue(industryName);
                row3.createCell(4).setCellValue(regionName);
                row3.createCell(5).setCellValue(vehicleType);
                row3.createCell(6).setCellValue(enterpriseName);
                row3.createCell(7).setCellValue(alarmTypeName);
                row3.createCell(8).setCellValue(jsonObject.getString("spanTime"));
                row3.createCell(9).setCellValue(jsonObject.getString("startTime"));

            }

            String fileName="报警超时推送表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "下级平台报文管理导出按钮")
    @RequestMapping(value = "/subordinateMessageExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getSubordinateMessageExcelOut(String startTime,String endTime,Integer uId,Integer platformIds,String messageObjectType,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("下级平台报文表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("下级平台报文表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("报文对象");
            row2.createCell(1).setCellValue("发送内容");
            row2.createCell(2).setCellValue("应答结果");
            row2.createCell(3).setCellValue("应答状态");
            row2.createCell(4).setCellValue("发送时间");
            List<Map<String,Object>> pwMessageList=postMessageService.selectSubordinate(startTime,endTime,uId,messageObjectType,platformIds);
            for (int i = 0; i < pwMessageList.size(); i++) {
                Map map=pwMessageList.get(i);
                //在sheet里创建第三行
                HSSFRow row3 = sheet.createRow(i + 2);
                String status="";
                if (String.valueOf(pwMessageList.get(0).get("isReply")).equals("1")){
                    status="已应答";
                }else {
                    status="未应答";
                }
                row3.createCell(0).setCellValue(String.valueOf(map.get("messageObjectType")));
                row3.createCell(1).setCellValue(String.valueOf(map.get("messageContent")));
                row3.createCell(2).setCellValue(String.valueOf(map.get("replyMessage")));
                row3.createCell(3).setCellValue(String.valueOf(map.get("status")));
                row3.createCell(4).setCellValue(String.valueOf(map.get("createTime")));
            }

            String fileName="下级平台报文表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "接入平台导出")
    @RequestMapping(value = "/joinPlatformPagingExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getJoinPlatformPagingExcelOut(String account,String loginName,String mobile,String loginFlag,Integer roleType,String platformCode,Integer level,Integer platformId,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("接入平台表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("接入平台表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("平台名称");
            row2.createCell(1).setCellValue("创建时间");
            row2.createCell(2).setCellValue("平台联系人");
            row2.createCell(3).setCellValue("平台类型");
            row2.createCell(4).setCellValue("绑定IP");
            row2.createCell(5).setCellValue("接入码");
            TDisPlatform disPlatform=new TDisPlatform();
            if (loginName.equals("null")){
                loginName=null;
            }
            disPlatform.setPlatformUsername(account);
            disPlatform.setPlatformName(loginName);
            disPlatform.setLoginFlag(loginFlag);
            disPlatform.setPlatformType(roleType);
            disPlatform.setPlatformCode(platformCode);
            disPlatform.setPlatformId(platformId);
            List<Map<String,Object>>userAll=tDisPlatformMapper.searchChoice(disPlatform);
            for (int i = 0; i < userAll.size(); i++) {
                Map map=userAll.get(i);
                String platformName=String.valueOf(map.get("platformName"));
                if (platformName.equals("null")){
                    platformName="";
                }
                String createTime=String.valueOf(map.get("createTime"));
                if (createTime.equals("null")){
                    createTime="";
                }
                String linkman=String.valueOf(map.get("linkman"));
                if (linkman.equals("null")){
                    linkman="";
                }
                String platformType=String.valueOf(map.get("platformType"));
                if (platformType.equals("null")){
                    platformType="";
                }
                String platformIds=String.valueOf(map.get("platformIp"));
                if (platformIds.equals("null")){
                    platformIds="";
                }
                String accessCode=String.valueOf(map.get("accessCode"));
                if (accessCode.equals("null")){
                    accessCode="";
                }
                //在sheet里创建第三行
                HSSFRow row3 = sheet.createRow(i + 2);
                row3.createCell(0).setCellValue(platformName);
                row3.createCell(1).setCellValue(createTime);
                row3.createCell(2).setCellValue(linkman);
                row3.createCell(3).setCellValue(platformType);
                row3.createCell(4).setCellValue(platformIds);
                row3.createCell(5).setCellValue(accessCode);
            }

            String fileName="接入平台表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }

    @ApiOperation(value = "报警明细统计导出")
    @RequestMapping(value = "/alarmStatisticsExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getAlarmStatisticsExcelOut(String date,String status,String regionCode,String eName,String vNumber,HttpServletRequest request,HttpServletResponse response){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("报警明细统计表");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("报警明细统计表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("车牌号码");
            row2.createCell(1).setCellValue("车牌颜色");
            row2.createCell(2).setCellValue("车辆属地管辖机构名称");
            row2.createCell(3).setCellValue("所属行业");
            row2.createCell(4).setCellValue("所属地区");
            row2.createCell(5).setCellValue("车辆类型");
            row2.createCell(6).setCellValue("所属企业");
            row2.createCell(7).setCellValue("在线状态");
            row2.createCell(8).setCellValue("超速报警");
            row2.createCell(9).setCellValue("疲劳驾驶");
            row2.createCell(10).setCellValue("偏航报警");
            row2.createCell(11).setCellValue("日期");
            String eIdsList="";
            String vIdlist="";
            String pIdList="";
            String eIds=null;
            String vIds=null;
            if (eName!=null && eName.equals("")==false){
                List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
                if (eIdsLists.size()>0){
                    for (int i = 0; i < eIdsLists.size(); i++) {
                        eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                    }
                    eIds=StringUtils.join(eIdsList.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            if (vNumber!=null && vNumber.equals("")==false){
                List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
                if (vehicleNumberList.size()>0){
                    for (int i = 0; i < vehicleNumberList.size(); i++) {
                        vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                    }
                    vIds=StringUtils.join(vIdlist.split(","),",");
                }else {
                    String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                    log.info(list);
                }
            }
            Map map=new HashMap();
            map.put("date",date);//必传 查询时间yyyy-MM-dd
            map.put("vIds",vIds);//车辆id，多个英文逗号分隔
            map.put("eIds",eIds);//企业id，多个英文逗号分隔
            map.put("status",status);//在线状态
            map.put("regionCode",regionCode);// 必填 用户所属行政区划
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) .equals("null")|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/alarmType/statisticDetails";
            String result= HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            for (int j = 0; j < jsonArray.size(); j++) {
                JSONObject jsonObject=jsonArray.getJSONObject(j);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String industryId=jsonObject.getString("industryId");//行业id
                Integer admidivcode= Integer.valueOf(jsonObject.getString("admdivcode"));//所属地区
                List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectVehicle(vId);//车辆名称
                String industryName=tDisDictionaryMapper.selectByItemValue(industryId);
                String administrationName=tRegionMapper.selectByoId(admidivcode);
                String aType=jsonObject.getString("alarmType");//报警类型
                Integer statusInt= Integer.valueOf(jsonObject.getString("status"));//在线状态
                String statusName="";
                if (statusInt==1){
                    statusName="在线";
                }else {
                    statusName="离线";
                }
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                if (enterpriseName==null){
                    enterpriseName="";
                }
                String vehicleName=tDisVehicleMapper.selectByVid(vId);
                if (vehicleName==null){
                    vehicleName="";
                }
                String regionName=tRegionMapper.selectAreaCode(admidivcode);
                if (regionName==null){
                    regionName="";
                }
                HSSFRow row3 = sheet.createRow(j + 2);
                if (vehicleList.size()==0){
                    row3.createCell(1).setCellValue("");
                    row3.createCell(5).setCellValue("");
                }else {
                    String vehicleType=tDisDictionaryMapper.selectVehicleType(String.valueOf(vehicleList.get(0).get("vehicleType")));//车辆类型
                    if (vehicleType==null){
                        vehicleType="";
                    }
                    String itemName=null;
                    if (String.valueOf(vehicleList.get(0).get("item_name"))==null){
                        itemName="";
                    }else {
                        itemName=String.valueOf(vehicleList.get(0).get("item_name"));
                    }
                    row3.createCell(1).setCellValue(String.valueOf(vehicleList.get(0).get("item_name")));
                    row3.createCell(5).setCellValue(String.valueOf(vehicleType));
                }

                //在sheet里创建第三行

                row3.createCell(0).setCellValue(vehicleName);
                row3.createCell(2).setCellValue(administrationName);
                row3.createCell(3).setCellValue(industryName);
                row3.createCell(4).setCellValue(regionName);
                row3.createCell(6).setCellValue(String.valueOf(enterpriseName));
                row3.createCell(7).setCellValue(statusName);
                row3.createCell(8).setCellValue(jsonObject.getString("overspeedCount"));
                row3.createCell(9).setCellValue(jsonObject.getString("fatigueDrivingCount"));
                row3.createCell(10).setCellValue(jsonObject.getString("yawCount"));
                row3.createCell(11).setCellValue(jsonObject.getString("date"));
            }

            String fileName="报警明细统计表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(java.net.URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();}
    }


    @ApiOperation(value = "业户管理导出按钮")
    @RequestMapping(value = "/enterpriseExcelOut",method = RequestMethod.GET)
    @JwtIgnore
    public void getEnterpriseExcelOut(Integer regionCode,Integer level,HttpServletRequest request,HttpServletResponse response,String enterpriseName){
        try {
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //创建新的sheet对象(excel的表单)
            HSSFSheet sheet = wb.createSheet("业户表");
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            sheet.setVerticallyCenter(true);
            HSSFRow row = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row.createCell(0);
            //设置单元格内容
            cell.setCellValue("业户表");
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(1);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("业户名称");
            row2.createCell(1).setCellValue("所属地区");
            row2.createCell(2).setCellValue("所属行业");
            row2.createCell(3).setCellValue("管辖机构");
            row2.createCell(4).setCellValue("经营状态");
            row2.createCell(5).setCellValue("经营范围");

 /*           Integer areaCode=null;
            if (level==1){
                areaCode= Integer.valueOf(String.valueOf(regionCode).substring(0,2));
            }else if (level==2){
                areaCode= Integer.valueOf(String.valueOf(regionCode).substring(0,4));
            }else if (level==3){
                areaCode= regionCode;
            }*/
            if (enterpriseName.equals("null")){
                enterpriseName=null;
            }
            List<Map<String,Object>> enterpriseList=tDisEnterpriseMapper.selectAll(enterpriseName);
            for (int i = 0; i < enterpriseList.size(); i++) {
                Map map=enterpriseList.get(i);
                Integer areaCodeName=Integer.parseInt(String.valueOf(map.get("regionCode")));
                String code=tRegionMapper.selectAreaCode(areaCodeName);
                if (code==null){
                    code="";
                }
                String industry=String.valueOf(map.get("industryId"));
                String industryName=tDisDictionaryMapper.selectIndustryId(industry);
                if (industryName==null){
                    industryName="";
                }
                String enterpriseNames=String.valueOf(map.get("enterpriseName"));
                if (enterpriseNames.equals("null")){
                    enterpriseNames="";
                }
                String administrationOrgniaztion= String.valueOf(map.get("administrationOrgniaztion"));
                if (administrationOrgniaztion.equals("null")){
                    administrationOrgniaztion="";
                }
                String managementForms= String.valueOf(map.get("managementForms"));
                if (managementForms.equals("null")){
                    managementForms="";
                }
                String scope= String.valueOf(map.get("scope"));
                if (scope.equals("null")){
                    scope="";
                }
                String platformName= String.valueOf(map.get("platformName"));

                //在sheet里创建第三行
                HSSFRow row3=sheet.createRow(i+2);
                row3.createCell(0).setCellValue(enterpriseNames);//业户名称
                row3.createCell(1).setCellValue(code);//所属地区
                row3.createCell(2).setCellValue(industryName);
                row3.createCell(3).setCellValue(administrationOrgniaztion);
                row3.createCell(4).setCellValue(managementForms);
                row3.createCell(5).setCellValue(scope);
            }
            String fileName="业户表.xls";
            OutputStream output=response.getOutputStream();
            if ("IE".equals(Browser.getBrowser(request))) {
                fileName = new String(URLEncoder.encode(fileName, "UTF-8"));
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }else{
                fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            }
            response.setHeader("Content-disposition", "attachment; filename="+fileName);
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
